#include "mclient.h"
#include "ui_mclient.h"

mClient::mClient(QWidget *parent) :
    QMainWindow(parent),
   // m_adv(new advertising(this)),
    ui(new Ui::mClient)
{
    ui->setupUi(this);


}

mClient::~mClient()
{
    delete ui;
}


void mClient::on_host_connect_bt_clicked()
{
    QString ip=ui->host_ip_le->text();
    int port=ui->host_port_le->text().toInt();
    qDebug()<<"ip"<<ip;
    qDebug()<<"port:"<<port;
    socket=new QTcpSocket;
    connect(socket,SIGNAL(connected()),this,SLOT(connect_host_success()));
    socket->connectToHost(ip,port);


    connect(socket,&QTcpSocket::readyRead,this,[this](){
       //获取通信套接字的内容
        QByteArray data = socket->readAll();
        QString str = QString::fromUtf8(data); // 假设服务器发送的是UTF-8编码的数据
        qDebug()<<str;
                    equipment_num="机器编号:"+str;
                    qDebug()<<equipment_num<<endl;
    });
   // m_adv->equipment_num_label=equipment_num;



}

void mClient::connect_host_success(void)
{
    ui->status_lb->setText("success to connect server");
    qDebug()<<"finish connect";

        advertising *new_board=new advertising(this);
        new_board->show();
        this->hide();



}



